﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Aria2c
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    public enum PosType
    {
        //头部
        [Description("POS_SET")]
        POS_SET,

        //当前位置
        [Description("POS_CUR")]
        POS_CUR,

        //尾部
        [Description("POS_END")]
        POS_END,
    }

    public sealed class Aria2cTools
    {
        private Aria2cTools()
        {

        }

        /// <summary>
        /// 获取枚举类型描述
        /// </summary>
        /// <param name="value"></param>
        /// <returns>返回描述，没有描述将直接返回枚举名称</returns>
        public static string GetEnumDescription(Enum value)
        {
            string str = value.ToString();
            System.Reflection.FieldInfo field = value.GetType().GetField(str);
            object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
            if (objs == null || objs.Length == 0)
            {
                return str;
            }

            System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
            return da.Description;
        }


        /// <summary>
        /// 根据路径获取文件目录
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <returns>文件目录</returns>
        public static string GetDirectoryName(string path)
        {
            return System.IO.Path.GetDirectoryName(path);
        }

        /// <summary>
        /// 根据路径获取文件名
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <returns></returns>
        public static string GetFileName(string path)
        {
            return System.IO.Path.GetFileName(path);
        }

        /// <summary>
        /// 根据路径获取文件名,不带后缀名
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <returns></returns>
        public static string GetFileNameWithoutExtension(string path)
        {
            return System.IO.Path.GetFileNameWithoutExtension(path);
        }

        /// <summary>
        /// 将纪元时间转换为标准时间
        /// </summary>
        /// <param name="second">从1970.1.1开始，到现在经过的秒数</param>
        /// <returns>UTC时间</returns>
        public static DateTime EpochToUtcTime(long second)
        {
            DateTime dateTime = new DateTime(1970, 1, 1);
            dateTime.AddSeconds(second);
            return dateTime;
        }

        /// <summary>
        /// 纪元时间转换为字符串
        /// </summary>
        /// <param name="second">从1970.1.1开始，到现在经过的秒数</param>
        /// <returns>UTC时间字符串</returns>
        public static string EpochToString(long second)
        {
            DateTime dateTime = new DateTime(1970, 1, 1);
            dateTime.AddSeconds(second);
            string dateString = dateTime.ToString("yyyy-MM-dd hh:mm:ss");
            return dateString;
        }

        /// <summary>
        /// 将UTC时间转换为字符串
        /// </summary>
        /// <param name="second">UTC时间</param>
        /// <returns>UTC时间字符串</returns>
        public static string DateTimeToString(DateTime dateTime)
        {
            string dateString = dateTime.ToString("yyyy-MM-dd hh:mm:ss");
            return dateString;
        }
    }
}
